﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Demo.CommonBase.View.Controllers;
using Demo.CommonBase.View.Contracts;
using Demo.Services.Services.Impl.Managers;
using Demo.Services.Contracts.DTO.Infos;
using Demo.CommonBase.Logging;
using Demo.CommonBase.Exceptions;
using System.Reflection;
using Demo.Services.Contracts.DTO.Filters;
using Demo.CommonBase.DTO.Infos;
using Demo.CommonBase.DTO.Filters;

namespace Demo.Services.View.Controllers
{
    public sealed class CommonController : AbstractDemoController
    {

        protected override void ConcreteExecute(IView view, string action)
        {
            try
            {
                switch (action)
                {
                    case "Services.GetProyectsByName":
                        GetProyectsByName(view);
                        break;
                    case "Services.GetResourceByName":
                        GetResourceByName(view);
                        break;
                    default: break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void GetProyectsByName(IView view)
        {
            ProyectManager proyetManager;
            CommonComboBoxPagingInfo proyects;
            ComboBoxFilter filter;
            try
            {
                Logger.Info();
                proyetManager = new ProyectManager();
                filter = (ComboBoxFilter)view.GetValue("ComboBoxFilter");
                proyects = proyetManager.GetProyectsByName(filter);
                view.SetValue("Proyects", proyects);

            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
        }

        private void GetResourceByName(IView view)
        {
            ResourceManager resourceManager;
            CommonComboBoxPagingInfo resources;
            ComboBoxFilter filter;
            try
            {
            
                Logger.Info();
                resourceManager = new ResourceManager();
                filter = (ComboBoxFilter)view.GetValue("ComboBoxFilter");
                resources = resourceManager.GetResourceByName(filter);
                view.SetValue("Resources", resources);

            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }
        }        

    }
}
